/*LICENSE_BEGIN
 * ******************************************************************
 * All original parts of SoccerScope2003 have copyright (2003) by
 * Team YowAI, represented by Mr. Shuhei Shiota
 * The Department of Creative Informatics
 * The Graduate School of Information Science and Technology
 * The University of Tokyo
 * 
 * Additional classes (except libraries in /lib) were developed by 
 * the Dainamite Robocup-Team of the DAI-Labor, TU-Berlin 
 * (www.dai-labor.de)
 * 
 * Extended/new classes/packages are:
 *   soccerscope.analyzer.LogfileAnalyzer
 *   soccerscope.daistatistic.*
 *   soccerscope.daistatistic.charts.*
 *   soccerscope.daistatistic.tools.*
 *   soccerscope.db.*
 *   soccerscope.dialog.*
 *   soccerscope.model.PlayerWorldModel
 *   soccerscope.model.SimplePlayer
 *   soccerscope.net.AgentConnector
 *   soccerscope.training.*
 *   soccerscope.training.conditions.*
 * ******************************************************************
LICENSE_END*/
package soccerscope.model;

import java.io.Serializable;
import java.util.Vector;

public class PlayMode implements Serializable {

    /**
     * id for serialization. 
     */
    private static final long serialVersionUID = 3256726186435426101L;

	public final static int PM_Null = 0;

	public final static int PM_BeforeKickOff = 1;

	public final static int PM_TimeOver = 2;

	public final static int PM_PlayOn = 3;

	public final static int PM_KickOff_Left = 4;

	public final static int PM_KickOff_Right = 5;

	public final static int PM_KickIn_Left = 6;

	public final static int PM_KickIn_Right = 7;

	public final static int PM_FreeKick_Left = 8;

	public final static int PM_FreeKick_Right = 9;

	public final static int PM_CornerKick_Left = 10;

	public final static int PM_CornerKick_Right = 11;

	public final static int PM_GoalKick_Left = 12;

	public final static int PM_GoalKick_Right = 13;

	public final static int PM_AfterGoal_Left = 14;

	public final static int PM_AfterGoal_Right = 15;

	public final static int PM_Drop_Ball = 16;

	public final static int PM_OffSide_Left = 17;

	public final static int PM_OffSide_Right = 18;

	public final static int PM_PK_Left = 19;

	public final static int PM_PK_Right = 20;

	public final static int PM_FirstHalfOver = 21;

	public final static int PM_Pause = 22;

	public final static int PM_Human = 23;

	public final static int PM_Foul_Charge_Left = 24;

	public final static int PM_Foul_Charge_Right = 25;

	public final static int PM_Foul_Push_Left = 26;

	public final static int PM_Foul_Push_Right = 27;

	public final static int PM_Foul_MultipleAttacker_Left = 28;

	public final static int PM_Foul_MultipleAttacker_Right = 29;

	public final static int PM_Foul_BallOut_Left = 30;

	public final static int PM_Foul_BallOut_Right = 31;

	public final static int PM_Back_Pass_Left = 32;

	public final static int PM_Back_Pass_Right = 33;

	public final static int PM_Free_Kick_Fault_Left = 34;

	public final static int PM_Free_Kick_Fault_Right = 35;

	public final static int PM_PenaltySetup_Left = 36;

	public final static int PM_PenaltySetup_Right = 37;

	public final static int PM_PenaltyReady_Left = 38;

	public final static int PM_PenaltyReady_Right = 39;

	public final static int PM_PenaltyTaken_Left = 40;

	public final static int PM_PenaltyTaken_Right = 41;

	public final static int PM_PenaltyMiss_Left = 42;

	public final static int PM_PenaltyMiss_Right = 43;

	public final static int PM_PenaltyScore_Left = 44;

	public final static int PM_PenaltyScore_Right = 45;

	public final static int PM_MAX = 46;

	public enum PLAY_MODE {
		PM_Null, PM_BeforeKickOff, PM_TimeOver, PM_PlayOn, PM_KickOff_Left, PM_KickOff_Right, PM_KickIn_Left, PM_KickIn_Right, PM_FreeKick_Left, PM_FreeKick_Right, PM_CornerKick_Left, PM_CornerKick_Right, PM_GoalKick_Left, PM_GoalKick_Right, PM_AfterGoal_Left, PM_AfterGoal_Right, PM_Drop_Ball, PM_OffSide_Left, PM_OffSide_Right, PM_PK_Left, PM_PK_Right, PM_FirstHalfOver, PM_Pause, PM_Human, PM_Foul_Charge_Left, PM_Foul_Charge_Right, PM_Foul_Push_Left, PM_Foul_Push_Right, PM_Foul_MultipleAttacker_Left, PM_Foul_MultipleAttacker_Right, PM_Foul_BallOut_Left, PM_Foul_BallOut_Right, PM_Back_Pass_Left, PM_Back_Pass_Right, PM_Free_Kick_Fault_Left, PM_Free_Kick_Fault_Right, PM_PenaltySetup_Left, PM_PenaltySetup_Right, PM_PenaltyReady_Left, PM_PenaltyReady_Right, PM_PenaltyTaken_Left, PM_PenaltyTaken_Right, PM_PenaltyMiss_Left, PM_PenaltyMiss_Right, PM_PenaltyScore_Left, PM_PenaltyScore_Right
	}

	public static PLAY_MODE[] allPlayModes = { PLAY_MODE.PM_Null,
			PLAY_MODE.PM_BeforeKickOff, PLAY_MODE.PM_TimeOver,
			PLAY_MODE.PM_PlayOn, PLAY_MODE.PM_KickOff_Left,
			PLAY_MODE.PM_KickOff_Right, PLAY_MODE.PM_KickIn_Left,
			PLAY_MODE.PM_KickIn_Right, PLAY_MODE.PM_FreeKick_Left,
			PLAY_MODE.PM_FreeKick_Right, PLAY_MODE.PM_CornerKick_Left,
			PLAY_MODE.PM_CornerKick_Right, PLAY_MODE.PM_GoalKick_Left,
			PLAY_MODE.PM_GoalKick_Right, PLAY_MODE.PM_AfterGoal_Left,
			PLAY_MODE.PM_AfterGoal_Right, PLAY_MODE.PM_Drop_Ball,
			PLAY_MODE.PM_OffSide_Left, PLAY_MODE.PM_OffSide_Right,
			PLAY_MODE.PM_PK_Left, PLAY_MODE.PM_PK_Right,
			PLAY_MODE.PM_FirstHalfOver, PLAY_MODE.PM_Pause, PLAY_MODE.PM_Human,
			PLAY_MODE.PM_Foul_Charge_Left, PLAY_MODE.PM_Foul_Charge_Right,
			PLAY_MODE.PM_Foul_Push_Left, PLAY_MODE.PM_Foul_Push_Right,
			PLAY_MODE.PM_Foul_MultipleAttacker_Left,
			PLAY_MODE.PM_Foul_MultipleAttacker_Right,
			PLAY_MODE.PM_Foul_BallOut_Left, PLAY_MODE.PM_Foul_BallOut_Right,
			PLAY_MODE.PM_Back_Pass_Left, PLAY_MODE.PM_Back_Pass_Right,
			PLAY_MODE.PM_Free_Kick_Fault_Left,
			PLAY_MODE.PM_Free_Kick_Fault_Right, PLAY_MODE.PM_PenaltySetup_Left,
			PLAY_MODE.PM_PenaltySetup_Right, PLAY_MODE.PM_PenaltyReady_Left,
			PLAY_MODE.PM_PenaltyReady_Right, PLAY_MODE.PM_PenaltyTaken_Left,
			PLAY_MODE.PM_PenaltyTaken_Right, PLAY_MODE.PM_PenaltyMiss_Left,
			PLAY_MODE.PM_PenaltyMiss_Right, PLAY_MODE.PM_PenaltyScore_Left,
			PLAY_MODE.PM_PenaltyScore_Right };

	// TODO: add all playmodes:
	public static String getPlayModeString(PLAY_MODE pm) {
		if (pm == null)
			return null;
		if (pm == PLAY_MODE.PM_PlayOn) 			 return "play_on";
    	if (pm == PLAY_MODE.PM_BeforeKickOff)	 return "before_kick_off";
    	if (pm == PLAY_MODE.PM_CornerKick_Left)	 return "corner_kick_l";
    	if (pm == PLAY_MODE.PM_CornerKick_Right) return "corner_kick_r";
    	if (pm == PLAY_MODE.PM_KickIn_Left)	     return "kick_in_l";
    	if (pm == PLAY_MODE.PM_KickIn_Right)	 return "kick_in_r";
		return null;
	}

	public int pmode;

	public PlayMode() {
		this.pmode = PM_BeforeKickOff;
	}

	public PlayMode(PlayMode playmode) {
		this.pmode = playmode.pmode;
	}

	public PlayMode(int pmode) {
		this.pmode = pmode;
	}
    
    /**
     * Generates a list of PlayMode-Objects.
     * @param playmodes Playmodes which should be in the list
     * @return the object list of playmodes
     */
    public static Vector getListOfModes(PLAY_MODE [] playmodes) {
        Vector v = new Vector();
        
        for (int i = 0; i < playmodes.length; i++) {
            v.add(new PlayMode(getIndexFor(playmodes[i])));
        }
        
        return v;
    }

	@Override
  public String toString() {
		return toString(this.pmode);
	}

	public static String toString(int pmode) {
		String pmodeString = "";

		switch (pmode) {
		case PM_Null:
			pmodeString = "NULL";
			break;
		case PM_BeforeKickOff:
			pmodeString = "Before Kick Off";
			break;
		case PM_TimeOver:
			pmodeString = "Time Over";
			break;
		case PM_PlayOn:
			pmodeString = "Play On";
			break;
		case PM_KickOff_Left:
			pmodeString = "Kick Off Left";
			break;
		case PM_KickOff_Right:
			pmodeString = "Kick Off Right";
			break;
		case PM_KickIn_Left:
			pmodeString = "Kick In Left";
			break;
		case PM_KickIn_Right:
			pmodeString = "Kick In Right";
			break;
		case PM_FreeKick_Left:
			pmodeString = "FreeKick Left";
			break;
		case PM_FreeKick_Right:
			pmodeString = "FreeKick Right";
			break;
		case PM_CornerKick_Left:
			pmodeString = "CornerKick Left";
			break;
		case PM_CornerKick_Right:
			pmodeString = "CornerKick Right";
			break;
		case PM_GoalKick_Left:
			pmodeString = "GoalKick Left";
			break;
		case PM_GoalKick_Right:
			pmodeString = "GoalKick Right";
			break;
		case PM_AfterGoal_Left:
		case PM_AfterGoal_Right:
			pmodeString = "GOAL";
			break;
		case PM_Drop_Ball:
			pmodeString = "drop ball";
			break;
		case PM_OffSide_Left:
		case PM_OffSide_Right:
			pmodeString = "OffSide";
			break;
		case PM_PK_Left:
			pmodeString = "PK Left";
			break;
		case PM_PK_Right:
			pmodeString = "PK Right";
			break;
		case PM_FirstHalfOver:
			pmodeString = "First Half Over";
			break;
		case PM_Pause:
			pmodeString = "pause";
			break;
		case PM_Human:
			pmodeString = "human judge";
			break;
		case PM_Foul_Charge_Left:
			pmodeString = "foul change left";
			break;
		case PM_Foul_Charge_Right:
			pmodeString = "foul change right";
			break;
		case PM_Foul_Push_Left:
			pmodeString = "foul push left";
			break;
		case PM_Foul_Push_Right:
			pmodeString = "foul push right";
			break;
		case PM_Foul_MultipleAttacker_Left:
			pmodeString = "foul multiple attack left";
			break;
		case PM_Foul_MultipleAttacker_Right:
			pmodeString = "foul multiple attack right";
			break;
		case PM_Foul_BallOut_Left:
			pmodeString = "foul ballout left";
			break;
		case PM_Foul_BallOut_Right:
			pmodeString = "foul ballout right";
			break;
		case PM_Back_Pass_Left:
			pmodeString = "Back Pass Left";
			break;
		case PM_Back_Pass_Right:
			pmodeString = "Back Pass Right";
			break;
		case PM_Free_Kick_Fault_Left:
			pmodeString = "FreeKick Fault Left";
			break;
		case PM_Free_Kick_Fault_Right:
			pmodeString = "FreeKick Fault Right";
			break;
		case PM_PenaltySetup_Left:
			pmodeString = "Penalty setup Left";
			break;
		case PM_PenaltySetup_Right:
			pmodeString = "Penalty setup Right";
			break;
		case PM_PenaltyReady_Left:
			pmodeString = "Penalty Ready Left";
			break;
		case PM_PenaltyReady_Right:
			pmodeString = "Penalty Ready Right";
			break;
		case PM_PenaltyTaken_Left:
			pmodeString = "Penalty Taken Left";
			break;
		case PM_PenaltyTaken_Right:
			pmodeString = "Penalty Taken Right";
			break;
		case PM_PenaltyMiss_Left:
			pmodeString = "Penalty Miss Left";
			break;
		case PM_PenaltyMiss_Right:
			pmodeString = "Penalty Miss Right";
			break;
		case PM_PenaltyScore_Left:
			pmodeString = "Penalty Score Left";
			break;
		case PM_PenaltyScore_Right:
			pmodeString = "Penalty Score Right";
			break;
		case PM_MAX:
			pmodeString = "";
			break;
		}

		return pmodeString;
	}

	/**
	 * This method retrieves the index of a giben playmode -1 if none if found:
	 * 
	 * @param play_mode -
	 *            the given PLAY_MODE
	 * @return the index inside the array allPlayModes
	 */
	public static int getIndexFor(PLAY_MODE play_mode) {
		for (int i = 0; i < allPlayModes.length; i++) {
			if (allPlayModes[i] == play_mode)
				return i;
		}
		return -1;
	}
    
    
    /**
     * Compares this object with a given.
     * @param o object to compare
     * @return true if both are same PlayMode
     */
    public boolean equals(Object o) {
        if (!(o instanceof PlayMode)) {
            return false;
        }
        PlayMode p = (PlayMode) o;
        return p.pmode == pmode;
    }
    
    /**
     * Returns the PlayMode in the enumeration representation
     * @return the enumeration representation
     */
    public PLAY_MODE getPlayModeEnum() {
        return allPlayModes[pmode];
    }
}
